<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>FCS Web IDE</title>

  <!-- Disable pinch zooming -->
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />

  <!-- Workbench Icon/Manifest/CSS -->
  <link rel="icon" href="/favicon.ico" type="image/x-icon" />

  <meta id="vscode-workbench-builtin-extensions" data-settings="[]" />
  <meta id="vscode-workbench-web-configuration" data-settings="">

  <link data-name="vs/workbench/workbench.web.api" rel="stylesheet"
    href="./dist/vscode/vs/workbench/workbench.web.api.css" />

  <!-- Built in extension -->
  <script src="./dist/extensions.js"></script>
</head>

<body></body>

<!-- source -->
<!-- https://github.com/microsoft/vscode -->
<!-- https://github.com/microsoft/vscode-web-playground -->
<!-- https://github.com/Felx-B/vscode-web -->

<script>
  let config = {
    "productConfiguration": {
      "nameLong": "FCS Editor",
      "nameShort": "FCS Editor",
      "applicationName": "fcs-editor",
      "dataFolderName": ".fcs-editor",
      "version": "1.0.0"
    },
    "folderUri": {
      "scheme": "memfs",
      "path": "/code"
    }
  };
  const configElement = document.getElementById("vscode-workbench-web-configuration");
  configElement.attributes["data-settings"].value = JSON.stringify(config);

  let zipUrl = "";
  let hash = window.location.hash;
  if (hash.startsWith("#")) {
    zipUrl = hash.split("#")[1]
  }

  let playground = [
    {
      "packageJSON": {
        // https://code.visualstudio.com/api/references/extension-manifest
        "name": "vscode-web-playground",
        "version": "0.0.10",
        "publisher": "vscode",
        "engines": {
          "vscode": "^1.48.0"
        },
        // https://code.visualstudio.com/api/advanced-topics/using-proposed-api
        "enableProposedApi": true,
        // https://code.visualstudio.com/api/references/activation-events
        "activationEvents": [
          "onFileSystem:memfs",
        ],
        // https://docs.npmjs.com/cli/v7/configuring-npm/package-json#browser
        "browser": "./dist/extension",
        // https://code.visualstudio.com/api/references/contribution-points
        "contributes": {
          "configuration": {
            "title": "WebPlayground",
            "properties": {
              "WebPlayground.zipUrl": {
                "type": ["string", "null"],
                "default": zipUrl,
                "description": "ZIP URL."
              },
              "WebPlayground.codeChange": {
                "type": ["string"],
                "default": "",
                "description": "Code Change Time."
              },
            },
          },
        },
      },
      "extensionPath": "vscode-web-playground"
    },
  ]

  const extElement = document.getElementById(
    "vscode-workbench-builtin-extensions"
  );
  extElement.attributes["data-settings"].value = JSON.stringify([
    ...playground,
    ...extensions,
  ]);

  let baseUri = `${window.location.origin}`;
  self.require = {
    baseUrl: `${baseUri}/dist/vscode/`,
    paths: {
      "vscode-textmate": `${baseUri}/dist/lib/vscode-textmate/release/main`,
      "vscode-oniguruma": `${baseUri}/dist/lib/vscode-oniguruma/release/main`,
      "semver-umd": `${baseUri}/dist/lib/semver-umd/lib/semver-umd.js`,
    },
  };

</script>
<script src="./dist/vscode/vs/loader.js"></script>

<script src="./dist/vscode/vs/workbench/workbench.web.api.nls.js"></script>
<script src="./dist/vscode/vs/workbench/workbench.web.api.js"></script>
<script src="./dist/vscode/vs/code/browser/workbench/workbench.js"></script>

<script>
  // 加载 ZIP 包
  // let zipUrl = "https://fcs-ide.oss.cn-north-3.inspurcloudoss.com/default-python36.zip";
  // executeCommand("webPlayground.reloadZip", zipUrl);

  // 执行命令，关闭所有打开的窗口
  // executeCommand("openEditors.closeAll");

  // 获取 base64 格式的代码 ZIP 包
  // async function generateZip() {
  //   let data = await executeCommand("webPlayground.generateZip");
  //   console.log(data);
  // }
</script>

</html>